package com.seu.clab.farm.model.dao.mapper;

import com.seu.clab.farm.model.dao.entity.Contract;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

@Repository
public interface ContractMapper extends Mapper<Contract> {
    @Select("select cid,name,part_A,part_B,money from contract where part_A='${accountId}' and flag=${flag} and deleted=0")
    List<Map<String, Object>> getContract(Integer flag,String accountId);

    @Select("select * from contract where deleted=0 limit ${pageIndex},20 ")
    List<Contract> getList(Integer pageIndex);

    @Select("select count(*) from contract where deleted=0")
    Integer getCount();

    @Select("select if(flag=0,contract.pdf,s.sign) as url  from contract\n" +
            "  left join signature s on contract.cid = s.cid where contract.cid=${cid} and deleted=0")
    String getPdf(Long cid);

    @Select("select * from contract where" +
            " CONCAT (`name`,`part_A`,`part_B`) like '%${content}%' and deleted=0")
    List<Contract> getSearchContract(String content);

    @Select("select flag from contract where cid=${cid} limit 1")
    Integer getFlag(Long cid);

    @Select("select deleted from contract where cid=${cid} limit 1")
    Integer getDeleted(Long cid);
}